#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "RoomSwitchComponent.generated.h"

class URoomLightComponent;

UCLASS(Blueprintable, Abstract, ClassGroup =(RoomLight))
class PHOBIA_API URoomSwitchComponent : public UActorComponent
{
	GENERATED_BODY()

protected:
	virtual void BeginPlay() override;
	virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;

public:
	// 设置灯状态
	UFUNCTION(BlueprintCallable)
	void SetLightSwitch(bool bSwitchOn);

	// 开关灯
	UFUNCTION(BlueprintCallable)
	void ToggleLightSwitch();

	// 设置电闸
	UFUNCTION(BlueprintCallable)
	void SetElectric(bool bElectric);

protected:
	void UpdateState(bool bForceUpdate);
	void TurnOnLightImp();
	void TurnOffLightImp();
	TArray<URoomLightComponent*> GetRoomLightComponents();

private:
	UPROPERTY(Transient)
	bool bLightSwitchOn = false;

	UPROPERTY(Transient)
	bool bHasElectric = true; // TODO 暂时用 true，回头再说

	UPROPERTY(Transient)
	bool bLightOn = false;

	UPROPERTY(Transient)
	TArray<TObjectPtr<URoomLightComponent>> RoomLightComponents;
};
